package com.su.cotroller;

import com.su.common.bo.user.UserRegBo;
import com.su.common.vo.ReturnResult;
import com.su.service.ItripUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/api")
public class UserController {

    @Autowired
    private ItripUserService userService;

    /**
     * 检测是账号否存在
     * @param userCode 账号
     * @return
     */
    @GetMapping(value = "/ckusr")
    public ReturnResult checkUser(String userCode) {
        userService.checkUser(userCode);
        return ReturnResult.ok();
    }

    /**
     * 邮箱注册 会发送邮件
     * @param userRegBo
     * @return
     */
    @PostMapping("/doregister")
    public ReturnResult doregister(UserRegBo userRegBo) {
        userService.doregister(userRegBo);
        return ReturnResult.ok();
    }

    /**
     * 手机号注册 会发送验证码
     * @param userRegBo
     * @return
     */
    @PostMapping(value = "/doRegisterByPhone")
    public ReturnResult doRegisterByPhone(UserRegBo userRegBo) {
        userService.userRegister(userRegBo);
        return ReturnResult.ok();
    }

    /**
     * 邮箱激活
     * @param userCode
     * @param activationCode
     * @return
     */
    @GetMapping("/activate/{userCode}/{activationCode}")
    public ReturnResult activate(@PathVariable String userCode, @PathVariable String activationCode) {
        userService.activate(userCode, activationCode);
        return ReturnResult.ok();
    }

    @GetMapping("/validatephone")
    public ReturnResult validatephone( String userCode, String activationCode){
        userService.activationCode(userCode, activationCode);
        return ReturnResult.ok();
    }

}


